package Test;

public class 字符串相加 {
    public static String addStrings(String num1, String num2) {
        int m=num1.length()-1,n=num2.length()-1;
        int add=0;
        StringBuilder sb=new StringBuilder();
        while (m>=0||n>=0||add!=0){
            int x=m>=0?num1.charAt(m)-'0':0;
            int y=n>=0?num2.charAt(n)-'0':0;
            int sum=x+y+add;
            add=sum/10;
            sb.append(sum%10);
            m--;
            n--;
        }
        sb.reverse();
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println("addStrings(\"900\",\"500\") = " + addStrings("900", "500"));
    }
}
